/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.beans.factory.config;

import java.util.Set;

import org.springframework.beans.BeansException;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.lang.Nullable;

/**
 * AutowireCapableBeanFactory实现了BeanFactory接口，负责bean生命周期的管理。
 *
 * @author Juergen Hoeller
 * @see org.springframework.beans.factory.BeanFactoryAware
 * @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
 * @see org.springframework.context.ApplicationContext#getAutowireCapableBeanFactory()
 * @since 04.12.2003
 */
public interface AutowireCapableBeanFactory extends BeanFactory {

	//表示没有外部定义的自动装配
	int AUTOWIRE_NO = 0;

	//通过名称指示自动装配bean属性(适用于Bean所有属性的setter)
	int AUTOWIRE_BY_NAME = 1;

	//通过类型指示自动装配bean属性(适用于Bean所有属性的setter)
	int AUTOWIRE_BY_TYPE = 2;

	//构造函数
	int AUTOWIRE_CONSTRUCTOR = 3;

	//通过bean类的内省确定适当的自动装配策略,已弃用
	@Deprecated
	int AUTOWIRE_AUTODETECT = 4;

	//用于没有代理的时候，也能强制返回实例
	String ORIGINAL_INSTANCE_SUFFIX = ".ORIGINAL";


	/**
	 * 创建bean
	 */
	<T> T createBean(Class<T> beanClass) throws BeansException;

	Object createBean(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;

	/**
	 * 初始化bean
	 */
	Object initializeBean(Object existingBean, String beanName) throws BeansException;

	/**
	 * bean 初始化时候 的前置处理器
	 * 为给定的已存在的Bean实例应用{@link BeanPostProcessor BeanPostProcessors},
	 * 并调用他们的postProcessBeforeInitialization方法.返回的Bean实例可能是原生Bean的一个包装.
	 */
	Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName)
			throws BeansException;

	/**
	 * bean 初始化时候 的后置处理器
	 */
	Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName)
			throws BeansException;

	/**
	 * bean 的销毁
	 */
	void destroyBean(Object existingBean);

	/**
	 * 自动装配bean
	 */
	Object autowire(Class<?> beanClass, int autowireMode, boolean dependencyCheck) throws BeansException;

	/**
	 * 通过应用初始化之后(after-instantiation)的回调以及bean属性的后置处理(post-processing)
	 * 来对给定Bean内部的属性进行装配(e.g. 注解注入).
	 */
	void autowireBean(Object existingBean) throws BeansException;


	/**
	 * 自动装配bean的属性
	 */
	void autowireBeanProperties(Object existingBean, int autowireMode, boolean dependencyCheck)
			throws BeansException;

	/**
	 * 配置bean
	 */
	Object configureBean(Object existingBean, String beanName) throws BeansException;


	/**
	 * 解析bean
	 */
	<T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType) throws BeansException;

	Object resolveBeanByName(String name, DependencyDescriptor descriptor) throws BeansException;

	@Nullable
	Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException;

	@Nullable
	Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName,
							 @Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException;

	/**
	 * 应用bean的属性值
	 */
	void applyBeanPropertyValues(Object existingBean, String beanName) throws BeansException;


}
